<?php
session_start();
if (isset($_SESSION['admin_name'])) {
} else {
    header("Location: admin_login.php");
}
?>
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>留言板后台管理</title>
  <link rel="shortcut icon" href="../img/favicon.svg" type="image/x-icon">
  <link rel="stylesheet" href="../css/admin_index.css">
  <script src="../js/admin_index.js"></script>
  <script src="../js/jquery-3.6.0.js"></script>

</head>

<body>
  <div class="center">
    <div class="nav">
      <div id="input0" class="nav_list"><input type="button" id="0" value="用户管理" onclick="onnav(this.id);"></div>
      <div id="input1" class="nav_list"><input type="button" id="1" value="留言管理" onclick="onnav(this.id);"></div>
      <div class="nav_list" style="width: 60%;"></div>
      <div class="nav_list "><input type="text" value="欢迎! <?php echo $_SESSION['admin_pet'];?>"></div>
      <div class="nav_list "><input type="button" id="2" value="退出登录" onclick="location.href='admin_logout.php';"></div>
    </div>

    <div class="table_user" >
      <table>
        <tr>
          <td>昵称</td>
          <td>账号</td>
          <td>手机号</td>
          <td>注册时间</td>
          <td>操作</td>

        </tr>
        <?php
        setcookie("message-cookie", "wfbhiucafwbhiuwfbiu", time() + 3600);
        // 连接数据库
        require "../query_db.php";
        $sql = "SELECT * FROM user_info";  //指定查询表message_bord表中的所有列
        $result = mysqli_query($conn, $sql);  //mysqli_query()用于执行SQL查询，并返回结果集或查询错误信息
        if (!$result) {  //$result接收错误信息或查询成功结果
          die("数据查询失败: " . mysqli_error($conn));
        }
        while ($message_data = mysqli_fetch_array($result, MYSQLI_NUM)) {
          echo "
              <tr>
                <td>$message_data[0]</td>
                <td>$message_data[1]</td>
                <td>$message_data[3]</td>
                <td>$message_data[4]</td>
                <td>
                  <a href='user_delete.php?id=$message_data[1]'>删除</a>
                </td>
              </tr>
            ";
        }
        echo "
      </table>
    </div>
    <div class='table_message' >
      <table>
        <tr>
         <td>记录ID</td>
          <td>账号</td>
          <td>昵称</td>
          <td>标题</td>
          <td>留言内容</td>
          <td>留言时间</td>
          <td>操作</td>
        </tr>";
        $sql = "SELECT * FROM message_bord";  //指定查询表message_bord表中的所有列
        $result = mysqli_query($conn, $sql);  //mysqli_query()用于执行SQL查询，并返回结果集或查询错误信息
        if (!$result) {  //$result接收错误信息或查询成功结果
          die("数据查询失败: " . mysqli_error($conn));
        }
        while ($message_data = mysqli_fetch_array($result, MYSQLI_NUM)) {
          echo "
              <tr>
                <td>$message_data[0]</td>
                <td>$message_data[1]</td>
                <td>$message_data[2]</td>
                <td>$message_data[3]</td>
                <td>$message_data[4]</td>
                <td>$message_data[5]</td>
                <td>
                  <a href='message_delete.php?id=$message_data[0]'>删除</a>
                </td>
              </tr>
            ";
        }
        ?>
      </table>
    </div>
  </div>
</body>
</html>